//
//  HotPlaceCell.swift
//  QYer
//
//  Created by linhan on 15-4-7.
//  Copyright (c) 2015年 linhan. All rights reserved.
//

import Foundation
import UIKit
class FormImageCell: UITableViewCell
{
    private var _cellWidth:CGFloat = 0
    private var _cellHeight:CGFloat = 0
    private let ImageWidth:CGFloat = 62
    
    private var _imageView:CircleAvatar = CircleAvatar(radius: 31)
    
    private var _imageObject:AnyObject?
    var imageObject:Any?
    {
        didSet
        {
            if imageObject == nil
            {
                _imageView.image = nil
            }
            else if let url = imageObject as? String
            {
                _imageView.image = url
            }
            else if let image = imageObject as? UIImage
            {
                _imageView.image = image
            }
        }
    }
    
    
    init(style: UITableViewCellStyle, reuseIdentifier: String?, cellWidth:CGFloat, cellHeight:CGFloat)
    {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        _cellWidth = cellWidth
        _cellHeight = cellHeight
        setup()
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setup()
    {
        _imageView.frame = CGRectMake((_cellWidth - ImageWidth) * 0.5, (_cellHeight - ImageWidth) * 0.5, ImageWidth, ImageWidth)
        _imageView.clipsToBounds = true
        contentView.addSubview(_imageView)
        
        let icon:UIImageView = UIImageView()
        icon.image = UIImage(named:"profile_img_edit")
        icon.contentMode = .center
        icon.backgroundColor = UIColor(white: 0, alpha: 0.5)
        icon.layer.cornerRadius = _imageView.width * 0.5
        icon.layer.masksToBounds = true
        icon.frame = _imageView.frame
        contentView.addSubview(icon)
    }
    
    
    
}//end class
